/*
 * CreepSprintingSalmon.java
 *
 * Created on January 4, 2008, 1:11 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package hextd.creep;

import hextd.core.Context;
import java.awt.Color;
import java.awt.Shape;
import java.awt.Stroke;

/**
 *
 * @author hylke
 */
public class CreepSprintingSalmon extends CreepBaseDirectional {

	public static String type = "ss";
	//
	private int energy = 80;
	private int energyMax = 80;
	private long oldHealth;
	private boolean sprinting = false;
	private boolean recharging = false;
	private float oldSpeed;
	private float oldPower;
	private String infoText = "<h1>Sprinting Salmon</h1>" +
			"<p>" +
			"If a Sprinting Salmon takes damage, it tries to sprint out of harms way." +
			"</p>";

	/** Creates a new instance of CreepSprintingSalmon */
	public CreepSprintingSalmon() {
		super("Sprinting Salmon", true);
		this.damageColor = Creep.COLOR.OTHER;
		this.damageColorAnti = Creep.COLOR.OTHER;
	}

	@Override
	public String getType() {
		return type;
	}

	@Override
	protected void doInit(Context context, int owner, int path, float delay, long health, int price, int score, Creep.Size s) {
		super.doInit(context, owner, path, delay, health, price, score, s);
		if (cn != null) {
			cn.loadSvg("ss", "images/image2.svg");
		}
		this.oldHealth = health;
		this.oldSpeed = this.getSpeedMaxBase();
		this.oldPower = this.getPowerBase();
	}

	@Override
	public String getInfoString() {
		return this.infoText +
				"<p>" + super.getInfoString() + "</p>";
	}

	@Override
	public void doTick(int gameTime) {
		if (!this.sprinting && !this.recharging) {
			if (this.health < this.oldHealth) {
				this.sprinting = true;
				this.speedMaxBase = this.oldSpeed * 2;
				this.speedMax *= 2;
				this.powerBase = this.oldPower * 2;
				this.power *= 2;
				this.speed = this.speedMax;
			}
		}
		if (this.recharging) {
			this.energy++;
			if (this.energy >= this.energyMax) {
				this.recharging = false;
			}
		}
		if (this.sprinting) {
			this.energy -= 2;
			if (this.energy <= 0) {
				this.sprinting = false;
				this.recharging = true;
				this.speedMaxBase = this.oldSpeed;
				this.powerBase = this.oldPower;
				this.speedMax /= 2;
				this.power /= 2;
				if (this.speedMax > this.getSpeedMaxBase()) {
					this.speedMax = this.getSpeedMaxBase();
				}
				if (this.power > this.getPowerBase()) {
					this.power = this.getPowerBase();
				}
			}
		}
		super.doTick(gameTime);
		this.oldHealth = this.health;
	}

	@Override
	Color generateColor() {
		return null;
	}

	@Override
	Stroke generateStroke() {
		return null;
	}

	@Override
	Shape[] generateShapes() {
		return null;
	}

	@Override
	String getSvgName() {
		return "ss";
	}
}
